<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class CoustomerCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
       $user= \Auth::guard('api')->user();
        return [
        'status' => 1,
        'message'=>'请求数据成功',
        'data' => $this->collection->each(function(&$value)use($user){
            if ($value->user_id==0){
              if ($user->hasPermissionTo('hide')&&!$user->hasPermissionTo('all')){
                 $value->mobile=substr_replace($value->mobile,'****',3,4);
              }
            }
              return $value;
        })
    ];
    }
}
